package com.drink.yan.web.rest;

import com.drink.yan.intf.entity.YanTask;
import com.drink.yan.intf.entity.YanTaskDeal;
import com.drink.yan.intf.vo.TaskVo;
import com.drink.yan.intf.vo.YanTaskDealVo;
import com.drink.yan.svc.service.YanTaskService;
import com.drink.yan.web.rest.req.cmd.ApproveTaskCmd;
import com.drink.yan.web.rest.req.cmd.CancelActivityCmd;
import com.drink.yan.web.rest.req.cmd.CancelTaskCmd;
import com.drink.yan.web.rest.req.qry.PageTaskQry;
import com.meta.act.app.service.ISysNoticeService;
import com.meta.framework.common.core.controller.BaseController;
import com.meta.framework.common.core.page.TableResponseVo;
import com.meta.framework.core.ResponseVo;
import io.swagger.annotations.ApiOperation;
import org.apache.tools.ant.Task;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * java类简单作用描述
 *
 * @Title:
 * @Package: com.drink.yan.web.rest.app.
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2023/11/23 14:58
 * @Version: v2.0
 */
@RestController
@RequestMapping("/task")
public class TaskRest extends BaseController {

    private ISysNoticeService noticeService;

    @Resource
    private YanTaskService yanTaskService;

    @ApiOperation(value = "获取任务", notes = "获取任务", tags = {"PC"})
    @GetMapping("/page")
    public TableResponseVo<List<TaskVo>> listTask(PageTaskQry qry){
        startPage();
        List<TaskVo> list = yanTaskService.listTask(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "任务处理列表", notes = "任务处理列表", tags = {"PC"})
    @GetMapping("/deal/page")
    public TableResponseVo<List<YanTaskDealVo>> pageTask(PageTaskQry qry){

        startPage();
        List<YanTaskDealVo> list = yanTaskService.listDealTask(qry);

        return getResponseVoTable(list);
    }

    @ApiOperation(value = "任务详情", notes = "任务详情", tags = {"PC"})
    @GetMapping("/detail/{taskNo}")
    public ResponseVo<TaskVo> detail(@PathVariable Long taskNo){
        TaskVo yanTask = yanTaskService.getDetail(taskNo);

        return ResponseVo.success(yanTask);
    }

    @ApiOperation(value = "取消任务", notes = "取消任务", tags = {"PC"})
    @PostMapping("/cancel")
    public ResponseVo<YanTask> cancel(@RequestBody CancelTaskCmd cmd){
        YanTask yanTask = yanTaskService.cancelTask(cmd);

        return ResponseVo.success(yanTask);
    }

    @ApiOperation(value = "保存任务", notes = "保存任务", tags = {"PC"})
    @PostMapping("/save")
    public ResponseVo<YanTask> save(@RequestBody YanTask cmd){
        YanTask yanTask = yanTaskService.saveTask(cmd);

        return ResponseVo.success(yanTask);
    }

    @ApiOperation(value = "审核通过", notes = "审核通过", tags = {"PC"})
    @PostMapping("/check/succ")
    public ResponseVo<YanTaskDeal> checkSucc(@RequestBody ApproveTaskCmd cmd){
        YanTaskDeal yanTask = yanTaskService.checkSucc(cmd);

        return ResponseVo.success(yanTask);
    }

    @ApiOperation(value = "审核失败", notes = "审核失败", tags = {"PC"})
    @PostMapping("/check/fail")
    public ResponseVo<YanTaskDeal> checkFail(@RequestBody ApproveTaskCmd cmd){
        YanTaskDeal yanTask = yanTaskService.checkFail(cmd);

        return ResponseVo.success(yanTask);
    }

}
